<template>
  <div class="register">
    <el-form
      :model="registerData"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="registerData.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="registerData.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="registerData.email"></el-input>
      </el-form-item>
      <el-form-item label="电话号" prop="phone">
        <el-input v-model="registerData.phone"></el-input>
      </el-form-item>
      <el-form-item label="验证码" prop="answer">
        <el-input v-model="registerData.answer"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="register('ruleForm')"
          >立即注册</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
        <el-button type="primary" @click="$router.push('/login')"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { register } from "../api/index";
export default {
  data() {
    return {
      registerData: {
        username: "",
        password: "",
        email: "",
        phone: "",
        answer: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        email: [{ required: true, message: "请输入邮箱地址", trigger: "blur" }],
        phone: [{ required: true, message: "请输入电话号", trigger: "blur" }],
        answer: [{ required: true, message: "请输入验证码", trigger: "blur" }],
      },
    };
  },
  methods: {
    register() {
      register(this.registerData).then((res) => {
        console.log(res);
      });
    },
  },
};
</script>

<style scoped lang="scss">
.register{
  width: 100%;
  height: 100vh;
  display: flex;
  .demo-ruleForm{
    width: 600px;
    height: 700px;
    margin: auto;
  }
}
</style>